/*
 * Copyright 2011 Kim Lindhardt Madsen
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package dk.lindhardt.gwt.geie.server.convert;

import dk.lindhardt.gwt.geie.shared.Cell;
import dk.lindhardt.gwt.geie.shared.CellFormatKey;
import dk.lindhardt.gwt.geie.shared.Position;
import dk.lindhardt.gwt.geie.shared.DateCell;
import jxl.CellType;
import jxl.write.DateTime;
import jxl.write.WritableCell;
import jxl.write.WritableCellFormat;

/**
 * User: AnAmuser
 * Date: 13-08-11
 * <p/>
 * Converts date cells
 */
public class DateCellConverterStrategy implements CellConverterStrategy {

   public CellType[] getJXLTypes() {
      return new CellType[] {CellType.DATE, CellType.DATE_FORMULA};
   }

   public Class<? extends Cell> getGeieType() {
      return DateCell.class;
   }

   public WritableCell convert(Cell cell, WritableCellFormat cellFormat) {
      DateCell dateCell = (DateCell) cell;
      Position position = cell.getPosition();
      return new DateTime(position.getColumn(), position.getRow(), dateCell.getDateValue(), cellFormat);
   }

   public Cell convert(jxl.Cell cell, Position position, CellFormatKey cellFormat) {
      jxl.DateCell dateCell = (jxl.DateCell) cell;
      return new DateCell(
            dateCell.getDate(), position, cellFormat);
   }
}
